/* 
 * File:   nfa.h
 * Author: abhi
 *
 * Created on February 6, 2012, 12:15 PM
 */

#ifndef NFA_H
#define	NFA_H

#include <pthread.h>

#ifdef	__cplusplus
extern "C" {
#endif
    
    /*
    typedef struct Transition_t {
        char* source;
        char* symbol;
        char* destination;
    } Transition;
    */
    
    typedef struct Next_Closure_States {
        int state;
        int* nextStates;
        int nextStatesSize;
        int* closureStates;
        int closureSize;
    } NextClosureStates;
    
    typedef struct Transition_t {
        int source;
        int symbol;
        int destination;
    } Transition;

    typedef struct NFA_t {
        char** states; /* Q */
        int statesNum;
        char** alphabet; /* Σ */
        int epsilonIndex; /* index of ε in alphabet */
        int alphabetSize;
        int initStateIndex; /* q0 */
        Transition* transTbl; /* δ */
        int transTblSize;        
        int* finalStatesIndices; /* F */
        int finalStatesNum;
    } NFA;
    
    /* create structure to pass as argument to thread */
    typedef struct thread_arg {
        int state;
        NFA* nfa;
        NextClosureStates* nextClosure;
        int* prevActiveStates;
        int* nextActiveStates;
        char* parseStr;
        int* statesRemaining;
        pthread_mutex_t* threadMutex;
    } ThreadArg;
    
    char** getStrArr(int size, int stringLen);
    Transition* createTransitionTable(int size);
    NFA* createNFA(void);
    NextClosureStates* createNextClosureForStates(NFA* nfa);
    void* parseForState(void* arg);
    int checkIfStringInLanguage(NFA* nfa, NextClosureStates* statesClosure, char* parseStr);
    /* void readFile(char* filename); */
    


#ifdef	__cplusplus
}
#endif

#endif	/* NFA_H */

